package com.leozhang.portalssm.controller;


import com.leozhang.portalssm.entity.Equipment;
import com.leozhang.portalssm.entity.Equipmentbrand;
import com.leozhang.portalssm.entity.Sex;
import com.leozhang.portalssm.service.EquipmentBrandService;
import com.leozhang.portalssm.util.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("/equipmentbrand")
@Controller
public class EquipmentBrandController {

    @Autowired
    private EquipmentBrandService equipmentBrandService;

    @RequiresPermissions("permission:query")
    @RequestMapping("/list")
    public String equipmentList(){


        return "type/equipmentbrand/list";
    }

    @RequestMapping("/list/page")
    @ResponseBody
    public Result equipmentbrandListPage(@RequestParam(value = "pno",defaultValue = "1")int pno,
                              @RequestParam(value = "psize",defaultValue ="10")int psize,
                              @RequestParam(value="brandName",defaultValue = "")String brandName,
                              @RequestParam(value="sortField",defaultValue = "")String sortField,
                              @RequestParam(value="sortType",defaultValue = "")String sortType)
    {
        System.out.println("我是测试代码1"+equipmentBrandService.getListForPage(pno,psize,brandName,sortField,sortType));
        return equipmentBrandService.getListForPage(pno,psize,brandName,sortField,sortType);
    }



    @RequestMapping("/add/page")
    public String addPage(){

        return "type/equipmentbrand/add";
    }
    @RequestMapping("/add")
    public String addSex(Equipmentbrand equipmentbrand){
        equipmentBrandService.insertequipmentbrand(equipmentbrand);
        return "redirect:/equipmentbrand/list";
    }
    @RequestMapping("/edit/page")
    public String editPage(Long id, Model model){
        Equipmentbrand equipmentbrand = equipmentBrandService.selectequipmentBrandById(id);
        //这里的key命名为formData是为了写别的模块可以快速的改
        model.addAttribute("formData",equipmentbrand);
        return "type/equipmentbrand/edit";
    }

    @RequestMapping("/edit")
    public String sexEdit(Equipmentbrand equipmentBrand){
        equipmentBrandService.updateEquipmentBrand(equipmentBrand);
        return "redirect:/equipmentbrand/list";
    }

    @RequestMapping("/delete")
    public String brandDelete(Long id){
        equipmentBrandService.deleteequipmentById(id);
        return "redirect:/equipmentbrand/list";
    }
}
